home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / filesy~1 / mfsdefrg.zoo / portst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-24  |  2.9 KB  |  149 lines

  1. #include <fcntl.h>
  2. #include <mintbind.h>
  3. #include <stdio.h>
  4. #define PORTST
  5. #include "portst.h"
  6.  
  7.  
  8. /* C equivalents of bitop stuff ... maybe useable on other platforms */
  9.  
  10. int bit(map,bnum)
  11. void *map;
  12. long bnum;
  13. {
  14.     return ((unsigned short *)map)[bnum>>4] & (1<<(bnum & 0xf)) ? 1 : 0;
  15. }
  16.  
  17. /* No return value , it isn't used at present */
  18. void setbit(map,bnum)
  19. void *map;
  20. long bnum;
  21. {
  22.     ((unsigned short *)map)[bnum>>4] |= 1<<(bnum & 0xf);
  23. }
  24.  
  25. void clrbit(map,bnum)
  26. void *map;
  27. long bnum;
  28. {
  29.     ((unsigned short *)map)[bnum>>4] &= ~(1<<(bnum & 0xf));
  30. }
  31.  
  32. /* This stuff is *definitely* atari ST specific , there aren't any block special
  33.  * files that correspond to the physical drives under TOS or MiNT so these are
  34.  * simulated by trapping all open/read/write/lseek/close calls , which are only
  35.  * (at present) used for disk access anyway . If this changes then something
  36.  * cleverer will be required .
  37.  */
  38.  
  39. #undef open
  40. #undef close
  41. #undef read
  42. #undef write
  43. #undef lseek
  44.  
  45. #include <unistd.h>
  46.  
  47. /* Global variables to keep track of whats going on */
  48. static long block;    /* Physical sector pointed to */
  49. static int infd;    /* The fd used for access (ignored for now) */
  50. static int _write_ok;    /* Write allowed */
  51. static struct hdinfo _hdinf; /* Hard disk info */
  52. static char *devname;  /* copy of device name */
  53. static int device;
  54.  
  55. int new_open(char *file,int mode,unsigned omode)
  56. {
  57.     int err;
  58.     if(mode==O_RDWR) _write_ok=1;
  59.     device=(file[0] & ~32) - 'A' ;
  60.     if(file[1]!=':' || file[2] || device < 0 || device > 25 )
  61.                         return open(file,mode,omode);
  62.     if( (err=get_hddinf(device,&_hdinf,0)) )
  63.     {
  64.         extern char *hdd_err[];
  65.         fprintf(stderr,"Can't access %s: %s\n",file,hdd_err[err]);
  66.         device=-1;
  67.         return -1;
  68.     }
  69.  
  70.     /* Flush minixfs buffers */
  71.     Dcntl(0x101,file,0l);
  72.  
  73.     /* Suspend update */
  74.     Dcntl(0x10b,file,1);
  75.  
  76.     (void)Dlock(1,device);
  77.  
  78.     devname=strdup(file);
  79.  
  80.     infd=10;
  81.  
  82.     return 10;    /* Anything valid */
  83. }
  84.  
  85. int new_close(fd)
  86. int fd;
  87. {
  88.     if(fd!=infd) return close(fd);
  89.     (void)Dlock(0,device);
  90.     Dcntl(0x10b,devname,2);
  91.     return 0;
  92. }
  93.  
  94. long new_lseek(fd,pos,whence)
  95. int fd;
  96. long pos;
  97. int whence;
  98. {
  99.     if(fd!=infd) return lseek(fd,pos,whence);
  100.     if(whence!=SEEK_SET)
  101.     {
  102.         fprintf(stderr,"Only SEEK_SET allowed\n");
  103.         return -1;
  104.     }
  105.     block=pos/1024;
  106.     return pos;    /* BUG: no check for bad sector number here */    
  107. }
  108.  
  109. long new_read(fd,buf,len)
  110. int fd;
  111. void *buf;
  112. long len;
  113. {
  114.     int ret;
  115.     if(fd!=infd) return read(fd,buf,len);
  116.     ret=block_rwabs(2,buf,len/1024,block,&_hdinf);
  117.     if(ret) return 0;
  118.  
  119.     block+=len/1024;
  120.  
  121.     return len;
  122. }
  123.  
  124. long new_write(fd,buf,len)
  125. int fd;
  126. void *buf;
  127. long len;
  128. {
  129.     int ret;
  130.     if(fd!=infd) return write(fd,buf,len);
  131.     if(!_write_ok) return 0;
  132.     ret=block_rwabs(3,buf,len/1024,block,&_hdinf);
  133.     if(ret) return 0;
  134.  
  135.     block+=len/1024;
  136.     return len;
  137. }
  138.  
  139. void new_sync()
  140. {
  141. /* Do nothing */
  142. }
  143.  
  144. long set_size(blocks)
  145. long blocks;
  146. {
  147.     return set_lrecno(&_hdinf,blocks);
  148. }
  149.